########################
#
# Copyright 2011, Vanderbilt University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS"
# BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied.  See the License for the specific languaged governing 
# permissions and limitations under the License.
#
########################

import bitstringUtils as b

def strictPrior(previousSolutions, numWeights):
    """
    If a bit is weighted more heavily, it is more likely
    to become zero (that is, create a generalization).  Thus,
    we want to weight the bits such that those that have been
    one more frequently have a higher weight
    >>> strictPrior([b.makePolicy('101010'), b.makePolicy('111000')], 6)
    [3, 2, 3, 1, 2, 1]

    >>> strictPrior([], 6)
    [1, 1, 1, 1, 1, 1]
    """
    if previousSolutions:
        for p in previousSolutions:
            assert(b.policySize(p) == numWeights)
        return [sum([x[p] for x in previousSolutions],1) for p in range(numWeights)]    
    else:
        return [1]*numWeights

if __name__ == "__main__":
    import doctest
    doctest.testmod()
